package com.lixin.smartclassroom.ui.home.tab3.activity

import com.drake.brv.utils.bindingAdapter
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.getzhutilistsource
import com.lixin.smartclassroom.bean.DataListBean
import com.lixin.smartclassroom.databinding.ActivityTotalScoreBinding
import com.lixin.smartclassroom.ext.child_id
import com.lixin.smartclassroom.ext.user_role
import com.lixin.smartclassroom.ui.home.adapter.taskScore
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.visible

/**
 * Description 累计得分
 * Author: lwc
 * Date:2023/12/13 17:50
 */
class TotalScoreAct : BaseActivity<ActivityTotalScoreBinding>() {
    override fun getViewBinding() = ActivityTotalScoreBinding.inflate(layoutInflater)

    override fun topBarHide() = true
    override fun startPadding() = false
    private var taskType = ""
    private var totalScore = ""
    private lateinit var listBean: ArrayList<DataListBean>

    override fun iniView() {
        taskType = getIntentString("type")
        totalScore = getIntentString("totalScore")
        binding.recycler.taskScore()

        binding.apply {
            tvScore.text = totalScore.toDouble().toInt().toString()
            refresh.onRefresh {
                scopeNetLife {
                    listBean = when (user_role) {
                        1 -> getzhutilistsource("2", child_id).data!!
                        else -> getzhutilistsource("1").data!!
                    }
                    addData(listBean) {
                        if (binding.recycler.bindingAdapter.models?.size == 0) {
                            binding.state.showEmpty()
                            binding.recycler.gone()
                        } else {
                            binding.recycler.visible()
                        }
                        listBean.size == 100
                    }
                }
            }.autoRefresh()
        }
    }

    override fun onClick() {
        binding.apply {
            ivBack.onClick {
                finish()
            }
        }
    }

}